package com.zjx.bean;

import org.aspectj.weaver.ast.Test;

import java.beans.PropertyEditorSupport;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author zhaojiaxu
 * @date 2021/08/17 15:14
 **/
public class DatePropertyEditor extends PropertyEditorSupport {
	private String format = "yyyy-MM-dd";
	public void setFormat(String format){
		this.format = format;
	}
	@Override
	public void setAsText(String text) throws IllegalArgumentException {
		SimpleDateFormat sdf = new SimpleDateFormat(format);
		try {
			Date d = sdf.parse(text);
			this.setValue(d);
		} catch (ParseException e) {
			e.printStackTrace();
		}
	}
}

